package com.example.demo.controller;

import com.example.demo.bean.UmsMember;
import com.example.demo.service.UmsMemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Api(value = "商城用户Controller")
@Controller
@RequestMapping("ums")
@CrossOrigin
public class UmsMemberController {

    @Autowired
    UmsMemberService umsMemberService;

    @ApiOperation(value = "获取用户信息", notes = "根据用户id获取用户信息")
    @ApiImplicitParam(name = "id", value = "用户id", required = true, dataType = "String", paramType = "path")
    @GetMapping("/{id}")
    @ResponseBody
    public UmsMember getUmsMemberInfo(@PathVariable String id) {
        UmsMember umsMember = new UmsMember();
        umsMember.setId(id);
        return umsMemberService.get(umsMember);
    }
    @ApiOperation(value = "登录功能", notes = "根据用户账号判断用户是否存在")
    @ResponseBody
    @PostMapping()
    public UmsMember checkUmsMember(@RequestBody UmsMember umsMember) {
        return umsMemberService.get(umsMember);
    }
    @ApiOperation(value = "添加用户",notes = "创建新的账号")
    @PostMapping("/add")
    public UmsMember CreateNewAccount(@RequestBody UmsMember umsMember) {
           return umsMemberService.addone(umsMember);
    }
    @ApiOperation(value = "修改用户信息")
    @PostMapping("/update")
    @ResponseBody
    public UmsMember updateUmsMember(@RequestBody UmsMember umsMember) {
        return umsMemberService.update(umsMember);
    }
}

